package com.meituan.service.impl;

import com.meituan.dao.StoresDao;
import com.meituan.pojo.entity.Stores;
import com.meituan.pojo.req.StoresReq;
import com.meituan.pojo.resp.BaseResp;
import com.meituan.service.StoresService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StoresServiceImpl implements StoresService {
    @Autowired
    StoresDao storesDao;

    @Override
    public void insert(StoresReq storesReq) {
        Stores stores = new Stores();
        BeanUtils.copyProperties(storesReq,stores);
        storesDao.saveAndFlush(stores);
    }

    @Override
    public BaseResp findAll() {
        List<Stores> all = storesDao.findByState(1);
        return new BaseResp(1,"success",all);
    }

    @Override
    public BaseResp findByZid(Integer zid) {
        List<Stores> all=storesDao.findByZid(zid);
        return new BaseResp(1,"success",all);
    }

    @Override
    public BaseResp findByFid(Integer fid) {
        List<Stores> all=storesDao.findByFid(fid);
        return new BaseResp(1,"success",all);
    }

    @Override
    public void deleteById(int sid) {
        storesDao.deleteById(sid);
    }

}
